<template>
    <div>
        <el-card class="box-card" shadow="never">
            <i class="el-icon-search"></i>
            <span>筛选搜索</span>
            <el-row :gutter="10" style="margin-top:15px;">
               <el-col :span='6'>
                   <el-input v-model="phone" placeholder="请输入手机号">
                     <template slot="prepend">留言手机号</template>
                   </el-input>
                </el-col>
                <el-col :span="6">
                  <el-date-picker
                        style="width:100%"
                        v-model="start_date"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="留言起始日期">
                      </el-date-picker>
                 </el-col>
                 <el-col :span="6">
                   <el-date-picker
                         style="width:100%"
                         v-model="end_date"
                         type="date"
                         value-format="yyyy-MM-dd"
                         placeholder="留言截止日期">
                   </el-date-picker>
                  </el-col>
            </el-row>
            <el-row :gutter="20" class="yx_el_row">
                <el-col :span="4">
                    <el-button type="success" plain @click="search">筛选</el-button>
                </el-col>
            </el-row>
            <div class="yx_line"></div>
            <div style="margin-top:10px;">
              <i class="el-icon-tickets"></i>
              <span>数据列表</span>
            </div>
            <el-table class="yx_table" border :data="messagelist">
                <el-table-column type="index" label="序号" width="80">
                </el-table-column>
                <el-table-column prop="phone" label="留言人手机号" width="150">
                </el-table-column>
                <el-table-column prop="trade_no" label="流水号" width="120">
                </el-table-column>
                <el-table-column prop="car_no" label="车牌号" width="120">
                </el-table-column>
                <el-table-column prop="lt_bar_code" label="关联轮胎条码号" width="150">
                </el-table-column>
                <el-table-column prop="topic" label="留言内容" width="580">
                </el-table-column>
                <el-table-column prop="total_answer" label="回复数" width="80">
                </el-table-column>
                <el-table-column prop="created_at" label="留言时间" width="150">
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-link type="primary" @click="detail(scope.row.id)">详情</el-link>
                    </template>
                </el-table-column>
            </el-table>
            <Pagination :total_count="total_count" :getList="getList"></Pagination>
        </el-card>
    </div>
</template>

<script>
    import { getMessageList } from '@/api/message.js';
    import { getDate } from '@/utils/date.js';
    import Pagination from '@/components/Pagination.vue';
    export default {
        name: 'MessageList',
        components:{ Pagination },
        inject:['reload'],
        data() {
            return {
                messagelist:[],
                total_count:0,
                phone:'',
                start_date:getDate(30),
                end_date:getDate(0)
            }
        },
        methods: {
            getList(current_page,page_size){
                this.$store.dispatch('loadCurrentPageSize',page_size);
                var send_data={
                    current_page:current_page,
                    page_size:page_size,
                    phone:this.phone,
                    start_date:this.start_date,
                    end_date:this.end_date
                }
                let that=this;
                getMessageList(send_data).then(function(response){
                    if(response.data.code==1){
                      that.messagelist=response.data.list;
                      that.total_count=response.data.total_count;
                    }
                });
            },
            search(){
               this.getList(1,this.$store.getters.getCurrentPageSize);
            },
            add(){
                this.$router.push({
                    name:'messageEdit',
                    params:{id:-1,edit_type:1}
                });
            },
            edit(id,edit_type){
                this.$router.push({
                    name:'messageEdit',
                    params:{id:id,edit_type:edit_type}
                });
            },
            del(id){
                let that=this;
                this.$confirm('确认删除, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then((e) => {
                    var send_data={
                        id:id,
                        is_delete:1
                    };
                    delMessage(send_data).then(function(response){
                        let type=response.data.code==1?'success':'error';
                        that.$message({
                            message:response.data.msg,
                            type:type,
                            onClose:function(e){
                                that.reload();
                            }
                        });
                    })
                })
            },
            detail(id){
                this.$router.push({
                    name:'messagedetail',
                    params:{id:id}
                });
            }
        },
        created() {
            this.getList(1,this.$store.state.default_page_size);
        },
    }
</script>
